package cn.achao.csr.zfb.controller;

import cn.achao.csr.api.model.dto.AliFundTransCommonQueryDTO;
import cn.achao.csr.api.model.dto.AliTradePagePayDTO;
import cn.achao.csr.api.model.dto.AliTransUniTransferDTO;
import cn.achao.csr.base.resp.R;
import cn.achao.csr.log.annotation.CsrLog;
import cn.achao.csr.zfb.service.AliPayService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付宝支付相关接口
 * @Author: achao
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/aliPay")
public class AliPayController {


    private final AliPayService aliPayService;

    /**
     * 统一收单下单跳转支付页面
     * @param dto
     * @return
     */
    @CsrLog(title = "统一收单下单跳转支付页面")
    @PostMapping("/trade/page/pay")
    public R<?> tradePagePay(@RequestBody @Validated AliTradePagePayDTO dto) {
        log.info("统一收单下单跳转支付页面");

        Map<String, String> res = new HashMap<>();
        res.put("formStr", aliPayService.tradePagePay(dto));
        return R.ok(res);
    }

    /**
     * 商家单笔转账
     * @return
     */
    @CsrLog(title = "单笔转账接口")
    @PostMapping("/trans/uni/transfer")
    public R<?> transUniTransfer(@RequestBody @Validated AliTransUniTransferDTO dto) {
        aliPayService.transUniTransfer(dto);
        return R.ok();
    }

    @CsrLog(title = "转账业务单据查询接口")
    @GetMapping("/fund/trans/common/query")
    public R<?> fundTransCommonQuery(@RequestParam("dto") AliFundTransCommonQueryDTO dto) {
        return R.ok(aliPayService.fundTransCommonQuery(dto));
    }


}
